﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;

using ProjectBase.Core;

using $prjsn$.Common;
using $prjsn$.Data.Providers;

namespace $safeprojectname$
{
    public class TestSettingsProvider : ProjectSettingsProvider
    {
        /// <summary>
        /// This is very important overriden setting.
        /// This allowes unit tests to access the config.files etc.
        /// Different path for MS Unit tests runtime, NUnit ...
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public override string CreateAbsolutePath(string path)
        {
            var target = path.Replace('/', '\\');
            if (target.StartsWith("\\", StringComparison.Ordinal))
            {
                target = target.Remove(0, 1);
            }
            var domain = AppDomain.CurrentDomain.BaseDirectory;
            target = !domain.Contains(@"\TestResults\")
                   ? @"..\..\" + target // bin\debug
                   : @"..\..\..\Tests\$safeprojectname$\" + target;

            return Path.Combine(domain, target);
        }
        /// <summary>
        /// Important for correct file path setting for testing
        /// This allowes unit tests to access the \APP_DATA folder to interact with .xml data files
        /// Different path for MS Unit tests runtime, NUnit ...
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public override string CreateAppDataPath(string fileName)
        {
            var domain = AppDomain.CurrentDomain.BaseDirectory;

            var target = !domain.Contains(@"\TestResults\")
                       ? @"..\..\App_Data\" + fileName // bin\debug
                       : @"..\..\..\Tests\$safeprojectname$\App_Data\" + fileName; // to use test settings

            return Path.Combine(domain, target);
        }
    }
}